package email;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Random;

import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLStreamException;

public class PopDB {
	public static void main(String[] args) throws FileNotFoundException, XMLStreamException, FactoryConfigurationError {
		DBController db;

		db = new DBController("C:/Users/Ted/Desktop");

		int messageEntries = 50;

		String body = "TESTBODY";

		HashMap<Long, ReceivedMessage> messageMap = new HashMap<Long, ReceivedMessage>();
		ArrayList<Long> idList = new ArrayList<Long>();
		for (int i = 0; i < messageEntries; i++) {
			ReceivedMessage m = new ReceivedMessage();
			m.setSubject("Message: " + i);
			m.setBody(body);
			m.setBody("Today!");
			m.setFrom("Shady individuals");
			m.setDate(new Date());
			m.setId(m.hashCode());
			messageMap.put(m.getId(), m);
			idList.add(i, m.getId());
		}

		int threadEntries = 10;

		HashMap<String, String> attributes = new HashMap<String, String>();

		Random r = new Random(1000);
		Random rMessage = new Random(100);
		Random rMessageNum = new Random(500);

		long threadId = -1;
		for (int i = 0; i < threadEntries; i++) {
			Thread t = new Thread();
			t.setName("Thread: " + i);
			int numMessage = rMessageNum.nextInt(10);
			for (int j = 0; j < numMessage; j++) {
				int messageIndex = rMessage.nextInt(messageMap.keySet().size());
				long id = idList.get(messageIndex);
				t.addEmail(messageMap.get(new Long(id)));
			}

			t.setId(t.hashCode());
			if (threadId == -1) {
				threadId = t.getId();
			}
			try {
				db.addThread(t);
				// db.insert("Threads", "Thread", attributes, "RecvdTime");
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
